import java.util.*;

/*
 * public class ListNode {
 *   int val;
 *   ListNode next = null;
 *   public ListNode(int val) {
 *     this.val = val;
 *   }
 * }
 */

public class code1 {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     *
     * @param pHead1 ListNode类 
     * @param pHead2 ListNode类 
     * @return ListNode类
     */
    public ListNode Merge (ListNode cur1, ListNode cur2) {
        // 直接两个指针比较
        ListNode ret = new ListNode(-1);
        ListNode cur = ret;

        while(cur1 != null && cur2 != null) {
            if(cur1.val <= cur2.val) {
                cur.next = cur1;
                cur1 = cur1.next;
                cur = cur.next;
            } else {
                cur.next = cur2;
                cur2 = cur2.next;
                cur = cur.next;
            }
        }
        while(cur1!=null) {
            cur.next = cur1;
            cur1 = cur1.next;
            cur = cur.next;
        }
        while(cur2!=null) {
            cur.next = cur2;
            cur2 = cur2.next;
            cur = cur.next;
        }
        return ret.next;
    }
}